<?php
namespace App\Services;
use App\Models\LogRoleChat;
use App\DTOS\Admin\LogRoleChatSearchDTO;
use App\Utils\MyLog;

// 聊天日志
class LogRoleChatService
{
    /**
    * @var  \Illuminate\Database\Eloquent\Builder
    */


    public function paginate(LogRoleChatSearchDTO $DTO)
    {
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $roleId =$DTO->getRoleId();
        $createDateBegin = $DTO->getCreateDateBegin();
        $createDateEnd = $DTO->getCreateDateEnd();
        $serverId=$DTO->getGameArea();
        $model = new LogRoleChat();
        $model->setConnection('log_'.$serverId);
        /**条件判断**/
        if ($createDateBegin){
            $model = $model->where('logTime','>=',strtotime($createDateBegin));
        }
        if ($createDateEnd){
            $model = $model->where('logTime','<=',strtotime($createDateEnd));
        }
        if ($roleId){
            $model = $model->where('roleId',$roleId);
        }



        return $model->orderByDesc('id')->paginate($perPage,'*','page',$page);
    }

}
